package com.ruibang.glass.equipment.controller;


import com.alibaba.nacos.common.utils.CollectionUtils;
import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.DeviceStaticsReq;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.domain.req.device.HazardAccountReq;
import com.ruibang.glass.equipment.entity.device.HazardAccount;
import com.ruibang.glass.equipment.entity.device.ScrapReport;
import com.ruibang.glass.equipment.service.HazardAccountService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 隐患台账
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/hazard/account")
@Api(value = "隐患台账")
public class HazardAccountController {
    @Autowired
    private HazardAccountService hazardAccountService;

    @PostMapping("list")
    @ApiOperation(value = "隐患台账", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody HazardAccountReq accountReq) {
        return ResultBody.success(hazardAccountService.queryPage(accountReq));
    }

    @GetMapping("getById/{id}")
    @ApiOperation(value = "根据ID查询详情", response = ResultBody.class)
    public ResultBody getById(@PathVariable("id") String id) {
        return ResultBody.success(hazardAccountService.getById(id));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "修改添加", response = ResultBody.class)
    public ResultBody addOrUpdateCheck(@RequestBody HazardAccount hazardAccount) {
        return ResultBody.success(hazardAccountService.addOrUpdateCheck(hazardAccount));
    }

    @GetMapping("/deleteById/{id}")
    @ApiOperation(value = "删除", notes = "通过ID删除检维修信息")
    public ResultBody delete(@PathVariable(value = "id") String id) {
        hazardAccountService.lambdaUpdate().set(HazardAccount::getIsDelete, Constants.ONE_STR).eq(HazardAccount::getHazardId, id).update();
        return ResultBody.success();
    }


    @GetMapping("getDetail/{hazardId}")
    @ApiOperation(value = "查看详情", response = ResultBody.class)
    public ResultBody getDetail(@PathVariable("hazardId") String hazardId) {
        return ResultBody.success(hazardAccountService.getInfo(hazardId));
    }


    @PostMapping("/export")
    @ApiOperation(value = "数据导出", response = ResultBody.class)
//    @FrequencyControl(time = 15, count = 2, target = FrequencyControl.Target.IP)
//    @FrequencyControl(time = 30, count = 5, target = FrequencyControl.Target.IP)
    public void export(@RequestBody HazardAccountReq accountReq, HttpServletResponse response) {
        hazardAccountService.export(accountReq, response);
    }

    @PostMapping("statics")
    @ApiOperation(value = "隐患台账统计分析", response = ResultBody.class)
    public ResultBody deviceStatics(@RequestBody DeviceStaticsReq deviceStaticsReq) {
        return ResultBody.success(hazardAccountService.deviceStatics(deviceStaticsReq));
    }

}
